<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:fo="http://www.w3.org/1999/XSL/Format"
	xmlns:f="livcos.org/ns/xslt/function"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns="http://www.w3.org/1999/XSL/Format"
	xmlns:v="livcos.org/ns/view"
	exclude-result-prefixes="fo f xs v">
	
  <xsl:import href="/livcos.org/page/doc/view.xsl" />

	<xsl:template name="layout">
		<simple-page-master master-name="page_A4_landscape" page-width="29.7cm" page-height="21cm"
			margin-top="4mm" margin-bottom="4mm" margin-left="8mm" margin-right="8mm">
			<region-body margin-top="10mm" margin-bottom="1mm" margin-left="1mm" margin-right="1mm"/>
			<region-before extent="12mm" />
			<region-after extent="8mm" />
		</simple-page-master>
	</xsl:template>
	
	<xsl:template name="page-sequence">
		<page-sequence master-reference="page_A4_landscape">
			<static-content flow-name="xsl-region-before">
				<xsl:apply-templates select="v:head" mode="header"/>
			</static-content>
			<static-content flow-name="xsl-region-after">
				<xsl:apply-templates select="v:head" mode="footer"/>
			</static-content>
			<flow flow-name="xsl-region-body" font-size="8pt" font-family="Verdana">
				<xsl:apply-templates select="*"/>
			</flow>
		</page-sequence>
	</xsl:template>
	
	<xsl:template match="v:head" mode="header">
		<table table-layout="fixed" width="100%">
			<table-column column-width="25%"/>
			<table-column column-width="50%"/>
			<table-column column-width="25%"/>
			<table-body>
				<table-row>
					<table-cell padding="0pt">
						<block text-align="start">
							<xsl:if test="normalize-space($logo) != ''">
								<external-graphic src="{$logo}" content-height="25pt" vertical-align="middle"/>
							</xsl:if>
						</block>
					</table-cell>
					<table-cell padding="0pt">
						<block font-size="10pt" font-family="sans-serif" text-align="center" margin-top="15pt">
							<xsl:value-of select="v:context" />
							<xsl:text>: </xsl:text>
							<xsl:value-of select="v:title" />
						</block>
					</table-cell>
					<table-cell padding="0pt">
						<block font-size="10pt" font-family="sans-serif" text-align="end" margin-top="15pt">
						</block>
					</table-cell>
				</table-row>
			</table-body>
		</table>
	</xsl:template>
	
	<xsl:template match="v:head" mode="footer">
		<table table-layout="fixed" width="100%">
			<table-column column-width="20%"/>
			<table-column column-width="60%"/>
			<table-column column-width="20%"/>
			<table-body >
				<table-row>
					<table-cell padding="1pt">
						<block font-size="8pt" text-align="start">
						</block>
					</table-cell>
					<table-cell padding="1pt">
						<block font-size="8pt" text-align="center">
						</block>
					</table-cell>
					<table-cell padding="1pt">
						<block font-size="8pt" text-align="end">
							<xsl:variable name="l" select="normalize-space(v:last-modified)"/>
							<xsl:variable name="date" as="xs:dateTime" select="if ($l != '') then xs:dateTime($l) else current-dateTime()"/>
							<xsl:value-of select="format-date(xs:date($date), '[Y]-[M01]-[D01]')"/>
						</block>
					</table-cell>
				</table-row>
			</table-body>
		</table>
	</xsl:template>
	
</xsl:stylesheet>
